﻿namespace System;
/// <inheritdoc/>
public class AndNotSpecification<T> : CompositeSpecification<T>
{
    #region Ctor
    /// <inheritdoc/>
    public AndNotSpecification(ISpecification<T> left, ISpecification<T> right) : base(left, right) { }
    #endregion
    #region Public Methods
    /// <inheritdoc/>
    public override Expression<Func<T, bool>> GetExpression()
    {
        var rightExpression = Right.GetExpression();

        var bodyNot = Expression.Not(rightExpression.Body);
        var bodyNotExpression = Expression.Lambda<Func<T, bool>>(bodyNot, rightExpression.Parameters);
        return Left.GetExpression().And(bodyNotExpression);
    }
    #endregion
}
